<?php

/*
|--------------------------------------------------------------------------
| 后台路由
|--------------------------------------------------------------------------
|
| 统一命名空间 Admin
| 统一前缀 admin
| 用户认证统一使用 auth 中间件
| 权限认证统一使用 permission:权限名称
|
*/


/*
|--------------------------------------------------------------------------
| 管理员登录、退出、更改密码
|--------------------------------------------------------------------------
*/
Route::group(['namespace'=>'Admin','domain'=>config('app.admin_domain')],function (){
    //登录
    Route::get('login','AdminController@showLoginForm')->name('admin.loginForm');
    Route::post('login','AdminController@login')->name('admin.login');

    //退出
    Route::get('logout','AdminController@logout')->name('admin.logout')->middleware('auth:admin');
    //更改密码
    Route::get('change_my_password_form','AdminController@changeMyPasswordForm')->name('admin.changeMyPasswordForm')->middleware('auth:admin');
    Route::post('change_my_password','AdminController@changeMyPassword')->name('admin.changeMyPassword')->middleware('auth:admin');
});

/*
|--------------------------------------------------------------------------
| 后台公共页面
|--------------------------------------------------------------------------
*/
Route::group(['namespace'=>'Admin','domain'=>config('app.admin_domain'),'middleware'=>'auth:admin'],function (){
    //后台布局
    Route::get('/','IndexController@layout')->name('admin.layout');
    //后台首页
    Route::get('/index','IndexController@index')->name('admin.index');
    //后台文件上传
    Route::post('upload', 'AdminController@upload')->name('admin.upload.image');
    Route::post('upload/file', 'AdminController@uploadEditor')->name('admin.upload.file');

});

/*
|--------------------------------------------------------------------------
| 系统管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace'=>'Admin','domain'=>config('app.admin_domain'),'middleware'=>['auth:admin','permission:system']],function (){

    //后台管理员管理
    Route::group(['middleware'=>['permission:system.admin']],function (){
        Route::get('admin','AdminController@index')->name('admin');
        Route::get('admin/data','AdminController@data')->name('admin.data');
        //添加
        Route::get('admin/create','AdminController@create')->name('admin.create')->middleware('permission:system.admin.create');
        Route::post('admin/store','AdminController@store')->name('admin.store')->middleware('permission:system.admin.create');
        //编辑
        Route::get('admin/{id}/edit','AdminController@edit')->name('admin.edit')->middleware('permission:system.admin.edit');
        Route::put('admin/{id}/update','AdminController@update')->name('admin.update')->middleware('permission:system.admin.edit');
        //删除
        Route::delete('admin/destroy','AdminController@destroy')->name('admin.destroy')->middleware('permission:system.admin.destroy');
        //分配角色
        Route::get('admin/{id}/role','AdminController@role')->name('admin.role')->middleware('permission:system.admin.role');
        Route::put('admin/{id}/assignRole','AdminController@assignRole')->name('admin.assignRole')->middleware('permission:system.admin.role');
        //分配权限
        Route::get('admin/{id}/permission','AdminController@permission')->name('admin.permission')->middleware('permission:system.admin.permission');
        Route::put('admin/{id}/assignPermission','AdminController@assignPermission')->name('admin.assignPermission')->middleware('permission:system.admin.permission');
    });

    //角色管理
    Route::group(['middleware'=>'permission:system.role'],function (){
        Route::get('role','RoleController@index')->name('admin.role');
        Route::get('role/data','RoleController@data')->name('admin.role.data');
        //添加
        Route::get('role/create','RoleController@create')->name('admin.role.create')->middleware('permission:system.role.create');
        Route::post('role/store','RoleController@store')->name('admin.role.store')->middleware('permission:system.role.create');
        //编辑
        Route::get('role/{id}/edit','RoleController@edit')->name('admin.role.edit')->middleware('permission:system.role.edit');
        Route::put('role/{id}/update','RoleController@update')->name('admin.role.update')->middleware('permission:system.role.edit');
        //删除
        Route::delete('role/destroy','RoleController@destroy')->name('admin.role.destroy')->middleware('permission:system.role.destroy');
        //分配权限
        Route::get('role/{id}/permission','RoleController@permission')->name('admin.role.permission')->middleware('permission:system.role.permission');
        Route::put('role/{id}/assignPermission','RoleController@assignPermission')->name('admin.role.assignPermission')->middleware('permission:system.role.permission');
    });

    //权限管理
    Route::group(['middleware'=>'permission:system.permission'],function (){
        Route::get('permission','PermissionController@index')->name('admin.permission');
        Route::get('permission/data','PermissionController@data')->name('admin.permission.data');
        //添加
        Route::get('permission/create','PermissionController@create')->name('admin.permission.create')->middleware('permission:system.permission.create');
        Route::post('permission/store','PermissionController@store')->name('admin.permission.store')->middleware('permission:system.permission.create');
        //编辑
        Route::get('permission/{id}/edit','PermissionController@edit')->name('admin.permission.edit')->middleware('permission:system.permission.edit');
        Route::put('permission/{id}/update','PermissionController@update')->name('admin.permission.update')->middleware('permission:system.permission.edit');
        //删除
        Route::delete('permission/destroy','PermissionController@destroy')->name('admin.permission.destroy')->middleware('permission:system.permission.destroy');
    });

    //配置组
    Route::group(['middleware'=>'permission:system.config_group'],function (){
        Route::get('config_group','ConfigGroupController@index')->name('admin.config_group');
        Route::get('config_group/data','ConfigGroupController@data')->name('admin.config_group.data');
        //添加
        Route::get('config_group/create','ConfigGroupController@create')->name('admin.config_group.create')->middleware('permission:system.config_group.create');
        Route::post('config_group/store','ConfigGroupController@store')->name('admin.config_group.store')->middleware('permission:system.config_group.create');
        //编辑
        Route::get('config_group/{id}/edit','ConfigGroupController@edit')->name('admin.config_group.edit')->middleware('permission:system.config_group.edit');
        Route::put('config_group/{id}/update','ConfigGroupController@update')->name('admin.config_group.update')->middleware('permission:system.config_group.edit');
        //删除
        Route::delete('config_group/destroy','ConfigGroupController@destroy')->name('admin.config_group.destroy')->middleware('permission:system.config_group.destroy');
    });

    //配置项
    Route::group(['middleware'=>'permission:system.configuration'],function (){
        Route::get('configuration','ConfigurationController@index')->name('admin.configuration');
        //添加
        Route::get('configuration/create','ConfigurationController@create')->name('admin.configuration.create')->middleware('permission:system.configuration.create');
        Route::post('configuration/store','ConfigurationController@store')->name('admin.configuration.store')->middleware('permission:system.configuration.create');
        //编辑
        Route::put('configuration/update','ConfigurationController@update')->name('admin.configuration.update')->middleware('permission:system.configuration.edit');
        //删除
        Route::delete('configuration/destroy','ConfigurationController@destroy')->name('admin.configuration.destroy')->middleware('permission:system.configuration.destroy');
    });

    //登录日志
    Route::group(['middleware'=>'permission:system.login_log'],function (){
        Route::get('login_log','LoginLogController@index')->name('admin.login_log');
        Route::get('login_log/data','LoginLogController@data')->name('admin.login_log.data');
        Route::delete('login_log/destroy','LoginLogController@destroy')->name('admin.login_log.destroy');
    });

    //操作日志
    Route::group(['middleware'=>'permission:system.operate_log'],function (){
        Route::get('operate_log','OperateLogController@index')->name('admin.operate_log');
        Route::get('operate_log/data','OperateLogController@data')->name('admin.operate_log.data');
        Route::delete('operate_log/destroy','OperateLogController@destroy')->name('admin.operate_log.destroy');
    });

});


/*
|--------------------------------------------------------------------------
| 商品管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Admin', 'domain'=>config('app.admin_domain'), 'middleware' => ['auth:admin', 'operate.log','permission:product.index']], function () {
    //商品列表页面
    Route::get('product', 'ProductController@index')->name('product.index');
    Route::get('product/data', 'ProductController@data')->name('product.data');
    //添加商品
    Route::get('product/create', 'ProductController@create')->name('product.create')->middleware('permission:product.create');
    Route::post('product/store', 'ProductController@store')->name('product.store')->middleware('permission:product.store');
    //编辑商品
    Route::get('product/{id}/edit', 'ProductController@edit')->name('product.edit')->middleware('permission:product.edit');
    Route::put('product/{id}/update', 'ProductController@update')->name('product.update')->middleware('permission:product.update');
    //删除商品
    Route::delete('product/destroy', 'ProductController@destroy')->name('product.destroy')->middleware('permission:product.destroy');
    //下架商品
    Route::delete('product/soft_delete', 'ProductController@soft_delete')->name('product.soft_delete')->middleware('permission:product.soft_delete');
    //上架商品
    Route::delete('product/restore', 'ProductController@restore')->name('product.restore')->middleware('permission:product.restore');
});

/*
|--------------------------------------------------------------------------
| 小程序用户管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace'=>'Admin','domain'=>config('app.admin_domain'),'middleware'=>['auth:admin','permission:user']],function () {
    Route::get('user', 'UserController@index')->name('user');
    Route::get('user/data', 'UserController@data')->name('user.data');
    //用户详情
    Route::get('user/{id}/detail', 'UserController@detail')->name('user.detail');
    //一级好友
    Route::get('user/one_friends', 'UserController@one_friends')->name('user.one_friends');
    //二级好友
    Route::get('user/two_friends', 'UserController@two_friends')->name('user.two_friends');
});

/*
|--------------------------------------------------------------------------
| 订单管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace'=>'Admin','domain'=>config('app.admin_domain'),'middleware'=>['auth:admin','permission:order']],function () {
    Route::get('order', 'OrderController@index')->name('order');
    Route::post('order/refund', 'OrderController@refundOrder')->name('order.refund');//拒单
    Route::get('order/data', 'OrderController@data')->name('order.data');
    //修改物流单号
    Route::post('order/delivery','OrderController@delivery')->name('order.delivery')->middleware('permission:order.delivery');
    //查看订单详情
    Route::get('order/detail/{id}','OrderController@detail')->name('order.detail');
    //查看订单支付结果
    Route::get('order/payment_query/{no}','OrderController@payment_query')->name('order.query');
});

/*
|--------------------------------------------------------------------------
| 财务管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace'=>'Admin','domain'=>config('app.admin_domain'),'middleware'=>['auth:admin','permission:flow']],function () {
    Route::get('flow','FlowController@index')->name('flow');
    Route::get('flow/data','FlowController@data')->name('flow.data');
    Route::get('flow/detail/{id}','FlowController@detail')->name('flow.detail')->middleware('permission:flow.detail');

    //分润详情
    Route::get('rebate/detail/{id}','RebateController@detail')->name('rebate.detail');
});

/*
|--------------------------------------------------------------------------
| 商铺管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace'=>'Admin','domain'=>config('app.admin_domain'),'middleware'=>['auth:admin','permission:store']],function () {
    Route::get('store','StoreController@index')->name('store');
    Route::get('store/data','StoreController@data')->name('store.data');
    //添加商铺
    Route::get('store/create','StoreController@create')->name('store.create')->middleware('permission:store.create');
    Route::post('store/store','StoreController@store')->name('store.store');
    Route::get('store/{id}/edit','StoreController@edit')->name('store.edit')->middleware('permission:store.edit');
    Route::post('store/{id}/update','StoreController@update')->name('store.update');
    //通过审核
    Route::post('store/approve','StoreController@approve')->name('store.approve')->middleware('permission:store.approve');
    //关闭商铺
    Route::post('store/close','StoreController@close')->name('store.close')->middleware('permission:store.close');
    //打开已经关闭的商铺
    Route::post('store/open','StoreController@open')->name('store.open')->middleware('permission:store.open');
});

/*
|--------------------------------------------------------------------------
| 栏目管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Admin', 'domain'=>config('app.admin_domain'), 'middleware' => ['auth:admin', 'operate.log']], function () {
    //分类管理
    Route::group(['middleware' => 'permission:category'], function () {
        Route::get('category/data', 'CategoryController@data')->name('admin.category.data');
        Route::get('category', 'CategoryController@index')->name('admin.category');
        //添加分类
        Route::get('category/create', 'CategoryController@create')->name('admin.category.create')->middleware('permission:category.create');
        Route::post('category/store', 'CategoryController@store')->name('admin.category.store')->middleware('permission:category.create');
        //编辑分类
        Route::get('category/{id}/edit', 'CategoryController@edit')->name('admin.category.edit')->middleware('permission:category.edit');
        Route::put('category/{id}/update', 'CategoryController@update')->name('admin.category.update')->middleware('permission:category.edit');
        //删除分类
        Route::delete('category/destroy', 'CategoryController@destroy')->name('admin.category.destroy')->middleware('permission:category.destroy');
    });
});

/*
|--------------------------------------------------------------------------
| 客户管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Admin', 'domain'=>config('app.admin_domain'), 'middleware' => ['auth:admin', 'operate.log']], function () {
    Route::group(['middleware' => 'permission:customer'], function () {
        //查询门店
        Route::get('customer/data', 'CustomerController@data')->name('customer.data');
        Route::get('customer', 'CustomerController@index')->name('customer');
        //添加门店
        Route::get('customer/create', 'CustomerController@create')->name('customer.create');
        Route::post('customer/store', 'CustomerController@store')->name('admin.customer.store');
        //编辑门店
        Route::get('customer/{id}/edit', 'CustomerController@edit')->name('customer.edit');
        Route::post('customer/{id}/update', 'CustomerController@update')->name('customer.update');

        //删除门店
        Route::post('customer/destroy', 'CustomerController@destroy')->name('customer.destroy');
    });
});


/*
|--------------------------------------------------------------------------
| 取货门店管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Admin', 'domain'=>config('app.admin_domain'), 'middleware' => ['auth:admin', 'operate.log']], function () {
    Route::group(['middleware' => 'permission:delivery'], function () {
        //查询门店
        Route::get('delivery/data', 'DeliveryController@data')->name('delivery.data');
        Route::get('delivery', 'DeliveryController@index')->name('delivery');
        //添加门店
        Route::get('delivery/create', 'DeliveryController@create')->name('delivery.create')->middleware('permission:delivery.create');
        Route::post('delivery/store', 'DeliveryController@store')->name('delivery.store')->middleware('permission:delivery.create');
        //编辑门店
        Route::get('delivery/{id}/edit', 'DeliveryController@edit')->name('delivery.edit')->middleware('permission:delivery.edit');
        Route::post('delivery/{id}/update', 'DeliveryController@update')->name('delivery.update')->middleware('permission:delivery.edit');
        //关闭门店
        Route::post('delivery/close', 'DeliveryController@close')->name('delivery.close')->middleware('permission:delivery.close');
        //开启门店
        Route::post('delivery/open', 'DeliveryController@open')->name('delivery.open')->middleware('permission:delivery.open');

        //删除门店
        Route::post('delivery/destroy', 'DeliveryController@destroy')->name('delivery.destroy')->middleware('permission:delivery.destroy');
    });
});


/*
|--------------------------------------------------------------------------
| 订单评论管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Admin', 'domain'=>config('app.admin_domain'), 'middleware' => ['auth:admin', 'operate.log']], function () {
    Route::group(['middleware' => 'permission:comment'], function () {
        //查询评论
        Route::get('comment/data', 'OrderCommentController@data')->name('comment.data');
        Route::get('comment', 'OrderCommentController@index')->name('comment');
        Route::post('comment/audit', 'OrderCommentController@audit')->name('comment.audit');

    });
});


















/*
|--------------------------------------------------------------------------
| 资讯管理模块
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Admin', 'domain'=>config('admin_domain'), 'middleware' => ['auth:admin', 'permission:information', 'operate.log']], function () {
    //文章管理
    Route::group(['middleware' => 'permission:information.article'], function () {
        Route::get('article/data', 'ArticleController@data')->name('admin.article.data');
        Route::get('article', 'ArticleController@index')->name('admin.article');
        //添加
        Route::get('article/create', 'ArticleController@create')->name('admin.article.create')->middleware('permission:information.article.create');
        Route::post('article/store', 'ArticleController@store')->name('admin.article.store')->middleware('permission:information.article.create');
        //编辑
        Route::get('article/{id}/edit', 'ArticleController@edit')->name('admin.article.edit')->middleware('permission:information.article.edit');
        Route::put('article/{id}/update', 'ArticleController@update')->name('admin.article.update')->middleware('permission:information.article.edit');
        //删除
        Route::delete('article/destroy', 'ArticleController@destroy')->name('admin.article.destroy')->middleware('permission:information.article.destroy');
    });
    //标签管理
    Route::group(['middleware' => 'permission:information.tag'], function () {
        Route::get('tag/data', 'TagController@data')->name('admin.tag.data');
        Route::get('tag', 'TagController@index')->name('admin.tag');
        //添加
        Route::get('tag/create', 'TagController@create')->name('admin.tag.create')->middleware('permission:information.tag.create');
        Route::post('tag/store', 'TagController@store')->name('admin.tag.store')->middleware('permission:information.tag.create');
        //编辑
        Route::get('tag/{id}/edit', 'TagController@edit')->name('admin.tag.edit')->middleware('permission:information.tag.edit');
        Route::put('tag/{id}/update', 'TagController@update')->name('admin.tag.update')->middleware('permission:information.tag.edit');
        //删除
        Route::delete('tag/destroy', 'TagController@destroy')->name('admin.tag.destroy')->middleware('permission:information.tag.destroy');
    });

    //文章管理
    Route::group(['middleware' => 'permission:information.article'], function () {
        Route::get('new/data', 'NewController@data')->name('admin.new.data');
        Route::get('new', 'NewController@index')->name('admin.new');
        //添加
        Route::get('new/create', 'NewController@create')->name('admin.new.create')->middleware('permission:information.new.create');
        Route::post('new/store', 'NewController@store')->name('admin.new.store')->middleware('permission:information.new.create');
        //编辑
        Route::get('new/{id}/edit', 'NewController@edit')->name('admin.new.edit')->middleware('permission:information.new.edit');
        Route::put('new/{id}/update', 'NewController@update')->name('admin.new.update')->middleware('permission:information.new.edit');
        //删除
        Route::delete('new/destroy', 'NewController@destroy')->name('admin.new.destroy')->middleware('permission:information.new.destroy');
    });
});
